#!/usr/bin/python2
# -*- coding: utf-8 -*-
# Name:     db.py
# Author:   xiooli <xioooli[at]yahoo.com.cn>
# Version:  111123

import sqlobject as sqlobj
from sqlobject.sqlite import builder

AND = sqlobj.AND
OR = sqlobj.OR

try:
    from lib.utils import Settings, SETTINGS_FILE
except:
    import sys
    sys.path.append('..')
    from utils import Settings, SETTINGS_FILE

db_file = Settings(SETTINGS_FILE).get_settings().db_file

conn = builder()(db_file)

class Pattern(sqlobj.SQLObject):
    _connection = conn
    name = sqlobj.StringCol(length = 200)
    polarity = sqlobj.StringCol(length = 1, default = '+')
    minmz = sqlobj.FloatCol()
    rule = sqlobj.StringCol()
    mol = sqlobj.StringCol()

Pattern.createTable(ifNotExists = True)

class PeriphGroup(sqlobj.SQLObject):
    _connection = conn
    name = sqlobj.StringCol(length = 200)
    exact_mass = sqlobj.FloatCol()
    mol = sqlobj.StringCol()

PeriphGroup.createTable(ifNotExists = True)

if __name__ == '__main__':
    p = Pattern.select()

    print list(p)[0].rule
